package lk.icta.core.entity;

import lk.icta.user.entity.User;
import org.codehaus.jackson.annotate.JsonManagedReference;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * @author Duminda Dharmakeerthi
 */
@Embeddable
public class LifeCycleInfo implements Serializable {

    @Column(nullable = false)
    @Temporal(value = TemporalType.TIMESTAMP)
    private Date createdTimeStamp;

    //TODO: set Lazy true and avoid collection iteration in JSON
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(nullable = false)
    private User createdUser;

    @Column(nullable = false)
    @Temporal(value = TemporalType.TIMESTAMP)
    private Date lastUpdatedTimeStamp;

    //TODO: set Lazy true and avoid collection iteration in JSON
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(nullable = false)
    private User lastUpdatedUser;

    public Date getCreatedTimeStamp() {
        return createdTimeStamp;
    }

    public void setCreatedTimeStamp(Date createdTimeStamp) {
        this.createdTimeStamp = createdTimeStamp;
    }

    @JsonManagedReference("user-lifecycle")
    public User getCreatedUser() {
        return createdUser;
    }

    public void setCreatedUser(User createdUser) {
        this.createdUser = createdUser;
    }

    public Date getLastUpdatedTimeStamp() {
        return lastUpdatedTimeStamp;
    }

    public void setLastUpdatedTimeStamp(Date lastUpdatedTimeStamp) {
        this.lastUpdatedTimeStamp = lastUpdatedTimeStamp;
    }

    @JsonManagedReference("user-lifecycle")
    public User getLastUpdatedUser() {
        return lastUpdatedUser;
    }

    public void setLastUpdatedUser(User lastUpdatedUser) {
        this.lastUpdatedUser = lastUpdatedUser;
    }
}
